const fp = require('lodash/fp');
const { Maybe, Container } = require('../utils/support.js');
let maybe = Maybe.of([5, 6, 1]);

//practice1
let ex1 = (arr) => {
  return fp.map((ele) => {
    return fp.add(ele, 1);
  }, arr);
};
maybe = maybe.map(ex1);
console.log('practice1_res:', maybe._value);

//practice2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);
let ex2 = (arr) => {
  return fp.first(arr);
};
const res2 = xs.map(ex2);
console.log('practice2_res:', res2._value);

//practice3
let safeProp = fp.curry(function (x, o) {
  return Maybe.of(o[x]);
});
let user = { id: 2, name: 'Albert' };
let ex3 = (obj) => {
  return fp.first(safeProp('name', obj)._value);
};
console.log('practice3_res:', ex3(user));

//practice4

let ex4 = function (n) {
  const maybe = Maybe.of(n);
  return maybe.map((v) => {
    return parseInt(v);
  })._value;
};
console.log('practice4_1_res:', ex4('100'));
console.log('practice4_2_res:', ex4(null));
